home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / call32 / abstract.txt next >
Encoding:
Text File  |  1996-09-11  |  5.8 KB  |  136 lines

  1.  CALL32: 32-bit DLL Calling Library for Visual Basic
  2.  
  3.  CALL32.DLL is a dynamic-link library (DLL) that can be
  4.  used for calling routines in 32-bit DLLs on the
  5.  Microsoft(R) Windows(R) NT(TM) and Windows95 (TM) operating 
  6.  systems. It cannot be used on Windows(TM) 3.1, Win32s(TM), 
  7.  or other operating systems. 
  8.  
  9.  Using it, a Visual Basic(R) program, running in
  10.  the Win16 subsystem, can declare and call functions in any
  11.  32-bit DLL (including, but not limited to, the system
  12.  DLLs). CALL32.DLL works on both the x86 and MIPS versions
  13.  on Windows NT. It has not been tested on Alpha or other
  14.  versions, but it should work.
  15.  
  16.  To call a function in a 32-bit DLL, follow these steps:
  17.  
  18.  1. Declare the following 2 function as follows (each all on 
  19.     one line):
  20.  
  21.      Declare Function Declare32 Lib "call32.dll" (ByVal Func$, ByVal Library$, ByVal Args$) As Long
  22.      Delcare Sub FreeCall32IDs Lib "call32.dll" ()
  23.  
  24.  2. Next, declare the function you wish to call. Declare it
  25.     in the ordinary fashion, with the following exceptions:
  26.  
  27.  >  Use a library name of "call32.dll"
  28.  >  Use an Alias of "Call32"
  29.  >  Add an additional argument at the end, of type ByVal Long
  30.  
  31.  For example, if you are calling the function:
  32.  
  33.  GetWindowText(HWND hwnd, LPSTR lpsz, int cch)
  34.  
  35.  declare it as follows (remember that ints and all handles
  36.  are 32 bits, so use a Long):
  37.  
  38.  Declare Function GetWindowText Lib "call32.dll" Alias "Call32" (ByVal hwnd As Long, ByVal lpsz As String, ByVal cch As Long, ByVal id As Long) As Long
  39.  
  40.  In the initialization section of your application, declare
  41.  the actual library and name of the function you want to
  42.  call with the Declare32 function. Pass it the name of the
  43.  function, the library, and a string describing the
  44.  argument types. Each letter in the string declares the
  45.  type of one argument, and should be either "i" for a 32-
  46.  bit integer or handle type, "p" for any pointer type, or
  47.  "w" for an HWND parameter to which you want to pass a 16-
  48.  bit HWND and have it be automatically converted to a 32-
  49.  bit HWND. Save the return value of Declare32 in a global
  50.  variable to pass as the last parameter to the function you
  51.  declared earlier. So, in continuing the example, you would
  52.  call:
  53.  
  54.  idGetWindowText = Declare32("GetWindowText", "user32", "wpi")
  55.  
  56.  (As a side note, this more properly would be declared as
  57.  "GetWindowTextA", since this is the real exported name.
  58.  However, Declare32 will automatically add an "A" to the
  59.  end of a function name if necessary.)
  60.  
  61.  To call the function, you would call:
  62.  
  63.  cbCopy = GetWindowText(hwnd, sz, cb, idGetWindowText)
  64.  
  65.  It is important to use the correct data types when calling
  66.  DLL functions. There are two important points to pay
  67.  attention to when using CALL32.DLL.
  68.  
  69.  First, only 32-bit integers can be passed to a DLL
  70.  procedure. Since virtually all 32-bit functions take int,
  71.  UINT, LONG, DWORD, or HANDLE parameters, which are all 32
  72.  bits, this is not a major restriction. However, you must
  73.  remember to always declare function arguments as Long, not
  74.  Integer.
  75.  
  76.  Second, 16-bit handles and 32-bit handles are not
  77.  interchangeable. For example, a 16-bit bitmap handle that
  78.  you get from calling a 16-bit DLL or from the Visual Basic
  79.  environment cannot be passed to a 32-bit function
  80.  expecting a bitmap handle. Similarly, a 32-bit handle
  81.  obtained from a 32-bit function cannot be passed to a 16-
  82.  bit DLL. The only exception is window handles (HWND). If
  83.  you declare a function parameter with the "w" letter in
  84.  the argument description string passed to Declare32, the
  85.  corresponding parameter will be automatically converted
  86.  from a 16-bit HWND to a 32-bit HWND when the call is made.
  87.  You must still declare the argument as a LONG. This is
  88.  convenient, for example, when passing the value returned
  89.  by the "hWnd" property of a control to a 32-bit DLL
  90.  function. Only windows created by your application can be
  91.  translated.
  92.  
  93.  The following is a summary of data types:
  94.  
  95.  C data type       Type specified in Declare   Character for Declare32
  96.    int, UINT          ByVal Long                 i
  97.    LONG, DWORD        ByVal Long                 i
  98.    HANDLE             ByVal Long                 i
  99.    WORD, short        not supported
  100.    HWND               ByVal Long                 w (i for no 16->32 translation)
  101.    LPSTR              ByVal String               p
  102.    LPLONG, LPDWORD,
  103.    LPUINT, int FAR *  Long                       p
  104.    LPWORD             Integer                    p
  105.  
  106.  Note on Declare32 function names: Declare32 will
  107.  automatically try three different names for the function
  108.  name you pass in. First, it uses the exact name you pass
  109.  in. If it doesn't find that function name, it converts the
  110.  name to the stdcall decorated name convention by adding an
  111.  underscore at the beginning and adding "@nn" at the end,
  112.  where "nn" is the number of bytes of arguments. If it
  113.  doesn't find that name, it adds an "A" to the end of the
  114.  original name to try the Win32(R) ANSI function calling
  115.  convention.
  116.  
  117.  *** NOTE ****
  118.  Before ending your VB programs, call FreeCall32IDs() to free 
  119.  the libraries that were loaded by CALL32.DLL.  If you don't call
  120.  this subroutine the counter that Windows keeps as to how many 
  121.  programs are using a particular .dll will not get decremented.
  122.  The .dlls are only removed from memory when the counter gets
  123.  decremented to 0.  By not calling the FreeCall32IDs() sub, you can
  124.  caused .dlls to remain in memory after your program exits.
  125.  
  126.  
  127.  This program is in the public domain. Feel free to
  128.  redistribute as you wish. No guarantees are made as to its
  129.  suitability or usefulness.
  130.  
  131.  CALL32 requires either the Microsoft Windows NT or Windows 95 
  132.  operating system to run. For information on run-time errors 
  133.  generated by CALL32, refer to the CALL32.TXT file.
  134.  
  135.  KEYWORDS: CD7
  136.